package itHeima.lesson8;

public class demo4 {
    /**
     * 数组复制
     *
     */
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4};
        int[] copy = Copy(arr);
        print(copy);
    }

    public static int[] Copy(int[] arr) {
        int[] newArr = new int[arr.length];
        for (int i = 0; i < newArr.length; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }

    public static void print(int[] copy) {
        System.out.print("[");
        for (int i = 0; i < copy.length; i++) {
            System.out.print(i == copy.length - 1 ? copy[i] : copy[i] + ",");
        }
        System.out.print("]");
    }
}
